package com.yc.damai.damaiuser.web;

import com.yc.damai.bean.Result;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * Company 源辰信息
 *
 * @author navy
 * @date 2024/9/4
 * Email haijunzhou@hnit.edu.cn
 */
@RestController
public class UserDo {

    @RequestMapping("user")
    String index(HttpServletRequest request){
        return "user " + request.getServerPort();
    }

    @RequestMapping("hello")
    String hello(String name){
        return "你好 " + name;
    }

    @RequestMapping("add")
    int add(@RequestParam("a") int a, @RequestParam("b") int b){
        return a + b;
    }

    @RequestMapping("sub/{x}/{y}")
    int sub(@PathVariable("x") int a, @PathVariable("y") int b){
        return a - b;
    }

    @RequestMapping("result")
    Result result(@RequestBody Result result){
        result.setCode( result.getCode() + 100);
        return result;
    }
    //获取session里面的验证码
    @RequestMapping("getcode")
    Result getcode(@SessionAttribute String vcode){
        if(vcode.isBlank()){
            return new Result(0,"验证码获取失败",null);
        }else {
            return new Result(1,"验证码获取成功",vcode);
        }
    }
}
